<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 初始化start */
        h1 {
            font-family: Verdana, Geneva, Tahoma, sans-serif;
            color: rgb(108, 180, 243);
            font-size: 50px;
        }

        body {
            background: url(./images/22.png) no-repeat;
            background-size: 1528px, 500px;
        }

        * {
            padding: 0;
            margin: 0;
        }

        input {
            outline: none;
        }

        a {
            text-decoration: none;
        }

        /* 初始化end */
        /* 版心 */
        .w {
            position: relative;
            width: 1200px;
            height: 1000px;
            margin: 0 auto;
        }

        /* 版心 */

        /* 公共 */
        .true {
            color: greenyellow;
        }

        .false {
            opacity: 0.6;
            color: red;
        }

        input {
            opacity: 0.8;
            width: 400px;
            height: 40px;
            text-indent: 20px;
            margin-top: 30px;
            border: 1px solid #f9ebeb;
            border-radius: 10px;
            box-shadow: 10px 10px 10px 0px rgb(152, 217, 249);
        }

        .box {
            position: absolute;
            left: 350px;
            width: 660px;
            height: 500px;

        }

        /* 公共 */

        /* 昵称 */
        .usename {
            margin-top: 100px;
        }

        .box .agreement {
            margin-left: 30px;
            margin-right: 16px;
            width: 16px;
            height: 16px;
            border: 0;
            box-shadow: none;
            vertical-align: text-bottom;
        }

        /* 昵称 */
        /* 提交按钮 */
        .next {
            width: 400px;
            height: 40px;
            margin-top: 30px;
            background-color: #49ba9b;
            text-align: center;
            line-height: 40px;
            font-size: 20px;
            color: #fff;
            opacity: 0.8;
        }

        /* 提交按钮 */

        /* 验证码 */
        .pinbox {
            position: relative;
        }

        .pinpp {
            position: absolute;
            right: 280px;
            top: 40px;
            opacity: 0.8;
        }

        /* 验证码 */
    </style>
</head>

<body>
    <h1>页面注册</h1>
    <!-- 表单模块 -->
    <div class="w">
        <div class="box">
            <div>
                <input type="text" placeholder="请输入昵称（昵称长度为6到10个字符）" class="usename">
                <span class="false usenamep"></span>
            </div>
            <div>
                <input type="text" placeholder="输入手机号码（请输入正确的手机号）" class="phone">
                <span class="false phonep"></span>
            </div>
            <div class="pinbox">
                <input type="text" placeholder="短信验证码（请输入正确的验证码）" class="pin">
                <span class="false pinp"></span>
                <button class="pinpp">获取验证码</button>
            </div>
            <div>
                <input type="password" placeholder="设置6至20位字母，数字和符号组合" class="passward">
                <span class="false passwardp"></span>
            </div>
            <div>
                <input type="password" placeholder="请再次输入上面的密码" class="repassward">
                <span class="false repasswardp"></span>
            </div>
            <div>
                <input type="checkbox" class="agreement">已阅读并同意<a href="#">《用户服务协议》</a>
            </div>
            <button class="next">下一步</button>
        </div>
    </div>

    <script>
        // 昵称模块
        const usename = document.querySelector('.usename')
        const usenamep = document.querySelector('.usenamep')
        usename.addEventListener('change', function un() {
            if (/^\W{6,10}$/.test(usename.value)) {
                usenamep.classList.remove('false')
                usenamep.classList.add('true')
                usenamep.innerHTML = '输入正确'
                return true
            }
            else {
                usenamep.classList.remove('true')
                usenamep.classList.add('false')
                usenamep.innerHTML = '您输入的格式有误'
                return false
            }
            if (!usename.value) {
                usenamep.innerHTML = ''
            }
        })


        // 手机号模块
        const phone = document.querySelector('.phone')
        const phonep = document.querySelector('.phonep')
        phone.addEventListener('input', function pe() {
            if (/^1\d{10}$/.test(phone.value)) {
                phonep.classList.remove('false')
                phonep.classList.add('true')
                phonep.innerHTML = '输入正确'
                return true
            }
            else {
                phonep.classList.remove('true')
                phonep.classList.add('false')
                phonep.innerHTML = '您输入的格式有误'
                return false
            }
        })
        // 验证码模块
        const pin = document.querySelector('.pin')
        const pinp = document.querySelector('.pinp')
        const pinpp = document.querySelector('.pinpp')
        pin.addEventListener('input', function pn() {
            if (/^\d{6}$/.test(pin.value)) {
                pinp.classList.remove('false')
                pinp.classList.add('true')
                pinp.innerHTML = '输入正确'
                return true
            }
            else {
                pinp.classList.remove('true')
                pinp.classList.add('false')
                pinp.innerHTML = '您输入的格式有误'
                return false
            }
        })
        pinpp.addEventListener('click', function () {
            let n = 10
            const time = setInterval(function () {

                pinpp.innerHTML = `重新获取验证码${n}`
                pinpp.disabled = true
                if (n === 0) {
                    clearInterval(time)
                    pinpp.innerHTML = '获取验证码'
                    pinpp.disabled = false
                }
                n--
            }, 1000)

        })

        // 密码模块
        const passward = document.querySelector('.passward')
        const passwardp = document.querySelector('.passwardp')
        passward.addEventListener('input', function pw() {
            if (/^\w{6,20}$/.test(passward.value)) {
                passwardp.classList.remove('false')
                passwardp.classList.add('true')
                passwardp.innerHTML = '输入正确'
                return true
            }
            else {
                passwardp.classList.remove('true')
                passwardp.classList.add('false')
                passwardp.innerHTML = '您输入的格式有误'
                return false
            }
        })
        // 重合密码模块
        const repassward = document.querySelector('.repassward')
        const repasswardp = document.querySelector('.repasswardp')
        repassward.addEventListener('input', function rw() {
            if (repassward.value === passward.value) {
                repasswardp.classList.remove('false')
                repasswardp.classList.add('true')
                repasswardp.innerHTML = '输入正确'
                return true
            }
            else {
                repasswardp.classList.remove('true')
                repasswardp.classList.add('false')
                repasswardp.innerHTML = '两次密码不一致'
                return false
            }
        })

        // 提交模块
        const form = document.querySelector('form')
        form.addEventListener('submit', function (e) {
            if (!un() || !pe() || !pn() || !pw() || !rw()) {
                alert('请核对信息')
                e.preventDefault()
            }
        })

    </script>
</body>

</html>